import React from 'react'
import { Card, Button, Table, Divider, Row, Modal } from 'antd'
import DescriptionList from 'components/DescriptionList'
import styles from './index.less'
import { contractOrderType, productType, contractOrderStatus, contractActionType } from 'utils/enumConfig'
import moment from 'moment'
import { LwjDownload, LwjSowPicList } from 'components'

/** @namespace currentItem.contractNum 合同号 */
/** @namespace currentItem.contractOrderType 合同订单类型 */
/** @namespace currentItem.productType 产品类型 */
/** @namespace currentItem.status 合同订单状态 */
/** @namespace currentItem.pushToOMSNeeded 是否需要推送OMS */
/** @namespace currentItem.designNeeded 是否需要设计 */
/** @namespace currentItem.orderContractAt 合同签订时间 */
/** @namespace currentItem.installContractAt 合同安装时间 */
/** @namespace currentItem.designAttachment 设计方案 */
/** @namespace currentItem.contractActionTypes 合同操作 */
/** @namespace currentItem.orderQuoteSummary */
/** @namespace currentItem.orderQuoteSummary.quoteAttachment 报价方案 */
/** @namespace currentItem.orderQuoteSummary.memo 报价备注 */
/** @namespace currentItem.orderQuoteSummary.quoteDeniedReason 报价不通过原因 */
/** @namespace currentItem.orderQuoteSummary.preOrderAmount 原订单金额 */
/** @namespace currentItem.orderQuoteSummary.decorationRebateAmount 装修返点金额 */
/** @namespace currentItem.orderQuoteSummary.cabinetRebateAmount 样柜返点金额 */
/** @namespace currentItem.orderQuoteSummary.eventsAmount 活动优惠金额 */
/** @namespace currentItem.orderQuoteSummary.orderAmount 订单金额 */
/** @namespace currentItem.contractOrderActivitySummaries 合同订单操作总结 */
const InstallationDetail = ({currentItem, dispatch}) => {
  const {Description} = DescriptionList
  /**
   * 派单信息字段
   * @type {*[]}
   */
  const workerInfoColumns = [{
    title: '工人',
    dataIndex: 'workerName',
    key: 'workerName',
  }, {
    title: '派单时间',
    dataIndex: 'dispatchTime',
    key: 'dispatchTime',
    render: (text, record) => (<span>{text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</span>)
  }, {
    title: '计划服务时间',
    dataIndex: 'plannedServiceTime',
    key: 'plannedServiceTime',
    render: (text, record) => (<span>{text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</span>)
  }, {
    title: '实际服务时间',
    dataIndex: 'serviceBeginTime',
    key: 'serviceBeginTime',
    render: (text, record) => (<span>{text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</span>)
  }, {
    title: '服务结束时间',
    dataIndex: 'serviceEndTime',
    key: 'serviceEndTime',
    render: (text, record) => (<span>{text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</span>)
  }]

  /**
   * 现场查验信息字段
   * @type {*[]}
   */
  const checkInfoColumns = [{
    title: '查验人',
    dataIndex: 'checkerName',
    key: 'checkerName',
  }, {
    title: '查验时间',
    dataIndex: 'checkTime',
    key: 'checkTime',
    render: (text, record) => (<span>{text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</span>)
  }, {
    title: '查验结果',
    dataIndex: 'checkStatus',
    key: 'checkStatus',
    render: (text, record) => (<span>{text === 'success' ? '完成' : '未完成'}</span>)
  }, {
    title: '包裹件数',
    dataIndex: 'packageNum',
    key: 'packageNum',
  }, {
    title: '外包装是否破损',
    dataIndex: 'packageOuter',
    key: 'packageOuter',
  }, {
    title: '五金件数量是否异常',
    dataIndex: 'hardwareNum',
    key: 'hardwareNum',
  }, {
    title: '现场环境是否异常',
    dataIndex: 'environment',
    key: 'environment',
  }]

  /**
   * 补件信息字段
   * @type {*[]}
   */
  const patchInfoColumns = [{
    title: '申请人',
    dataIndex: 'submitterName',
    key: 'submitterName',
    width: '10%'
  }, {
    title: '业主',
    dataIndex: 'customerName',
    key: 'customerName',
    width: '10%'
  }, {
    title: '补件原因',
    dataIndex: 'patchReason',
    key: 'patchReason',
    width: '10%'
  }, {
    title: '补件明细',
    dataIndex: 'patchRemark',
    key: 'patchRemark',
    width: '25%'
  }, {
    title: '查看图片',
    dataIndex: 'patchImg',
    key: 'patchImg',
    width: '45%',
    render: (text, record) => (<LwjSowPicList title='补件图片' fileLists={text}/>)
  }]

  /** @namespace currentItem.workerInfo */
  /** @namespace currentItem.checkInfo */
  /** @namespace currentItem.patchInfo */
  /** @namespace currentItem.installInfo */
  /** @namespace currentItem.installInfo.serviceEffectAttachment */
  return (
    <div>
      <Card bordered={false}>
        <DescriptionList size="large"
                         title="安装信息"
                         style={{marginBottom: 32}}>
          <Description
            term="期望安装时间">{currentItem.installInfo.expectServiceTime ? moment(currentItem.installInfo.expectServiceTime).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</Description>
          <Description term="业主姓名">{currentItem.installInfo.userName}</Description>
          <Description term="安装地址">{currentItem.installInfo.contactWay}</Description>
          <Description
            term="开始安装时间">{currentItem.installInfo.serviceStartTime ? moment(currentItem.installInfo.serviceStartTime).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</Description>
          <Description
            term="安装完成时间">{currentItem.installInfo.serviceEndTime ? moment(currentItem.installInfo.serviceEndTime).format('YYYY-MM-DD HH:mm:ss') : '暂无'}</Description>
        </DescriptionList>

        <Divider style={{marginBottom: 32}}/>

        {currentItem.workerInfo.length > 0 && <DescriptionList size="large"
                                                               title="派单信息"
                                                               style={{marginBottom: 32}}>
          <Table dataSource={currentItem.workerInfo} columns={workerInfoColumns} rowKey={'dispatchTime'}
                 pagination={false}/>
        </DescriptionList>}

        <Divider style={{marginBottom: 32}}/>

        {currentItem.checkInfo.length > 0 && <DescriptionList size="large"
                                                              title="现场查验信息"
                                                              style={{marginBottom: 32}}>
          <Table dataSource={currentItem.checkInfo} columns={checkInfoColumns} rowKey={'checkTime'} pagination={false}/>
        </DescriptionList>}

        <Divider style={{marginBottom: 32}}/>

        {currentItem.patchInfo.length > 0 && <DescriptionList size="large"
                                                              title="补件信息"
                                                              style={{marginBottom: 32}}>
          <Table dataSource={currentItem.patchInfo} columns={patchInfoColumns} pagination={false}/>
        </DescriptionList>}


        {currentItem.installInfo.serviceEffectAttachment &&
        <LwjSowPicList title='安装效果图' fileLists={currentItem.installInfo.serviceEffectAttachment}/>}
      </Card>
    </div>
  )
}

export default InstallationDetail
